from PySide2 import QtGui, QtCore, QtWidgets
from PySide2.QtWidgets import *
from PySide2.QtGui import *
from PySide2.QtCore import *
import sys


class Demo(QWidget):
    def __init__(self, parent=None):
        super(Demo, self).__init__(parent)
        self.setWindowTitle('画笔的设置')
        self.resize(300, 120)

    def paintEvent(self, event):
        painter = QPainter(self)
        pen = QPen()
        # 设置第一条直线的画笔
        pen.setColor(Qt.red)
        pen.setStyle(Qt.SolidLine)
        pen.setWidth(1)
        painter.setPen(pen)
        painter.drawLine(80, 10, 200, 10)
        # 设置第二条直线的画笔
        pen.setColor(Qt.blue)
        pen.setStyle(Qt.DashLine)
        pen.setWidth(2)
        painter.setPen(pen)
        painter.drawLine(80, 30, 200, 30)
        # 设置第三条直线的画笔
        pen.setColor(Qt.cyan)
        pen.setStyle(Qt.DotLine)
        pen.setWidth(3)
        painter.setPen(pen)
        painter.drawLine(80, 50, 200, 50)
        # 设置第四条直线的画笔
        pen.setColor(Qt.green)
        pen.setStyle(Qt.DashDotLine)
        pen.setWidth(4)
        painter.setPen(pen)
        painter.drawLine(80, 70, 200, 70)
        # 设置第五条直线的画笔
        pen.setColor(Qt.black)
        pen.setStyle(Qt.DashDotDotLine)
        pen.setWidth(5)
        painter.setPen(pen)
        painter.drawLine(80, 90, 200, 90)
        # 设置第六条直线的画笔
        pen.setColor(QColor(48, 235, 100))
        pen.setStyle(Qt.CustomDashLine)
        pen.setDashPattern([1, 3, 2, 3])
        pen.setWidth(6)
        painter.setPen(pen)
        painter.drawLine(80, 110, 200, 110)


if __name__ == '__main__':
    app = QApplication(sys.argv)
    demo = Demo()
    demo.show()
    sys.exit(app.exec_())




